/**
 * Copyright © 2022 易久批信息技术有限公司. All rights reserved.
 */
package com.dysm.pc;

import java.util.Random;
import java.util.concurrent.BlockingQueue;

/**
 *
 * @author xiay
 * @since 2022/4/6 7:54 下午
 */
public class BlockQueueProducer implements Runnable {

    private BlockingQueue<Integer> queue;

    public BlockQueueProducer(BlockingQueue<Integer> queue) {
        this.queue = queue;
    }


    @Override
    public void run() {
        while (true) {
            try {
                Thread.sleep(1000);
                queue.put(product());
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    private Integer product() {
        int nextInt = new Random().nextInt();
        System.out.println(Thread.currentThread().getName() +",生产者生产：" + nextInt);
        return nextInt;
    }
}
